//用双链表模拟实现队列
public class MyQueue1 {
    static class LinkNode {
        public LinkNode next;
        public LinkNode prev;
        public int val;
        public LinkNode(int val) {
            this.val = val;
        }
    }
    public LinkNode head;
    public LinkNode last;
    public int usedSize;

    //入队列
    public boolean offer(int val) {
        LinkNode newNode = new LinkNode(val);
        if(head == null) {
            head = newNode;
            last = newNode;
        }else {
            last.next = newNode;
            newNode.prev = last;
            last = last.next;
        }
        usedSize++;
        return true;
    }

    //出队列
    public int pop() {
        if(isEmpty()) {
            throw new EmptyException("队列空了");
        }
        int ret = head.val;
        head = head.next;
        if(head != null) {
            head.prev = null;
        }
        usedSize--;
        return ret;
    }

    //获取队首元素
    public int peek() {
        return head.val;
    }

    //判断是否为空
    public boolean isEmpty() {
        return head == null;
    }

    //获取大小
    public int size() {
        return usedSize;
    }



}
